<?php
namespace Tbf\Bundle\RouteBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
 * tbf 路由加载器
 */
class RouteLoaderCompilerPass implements CompilerPassInterface
{
    /**
     * You can modify the container here before it is dumped to PHP code.
     *
     * @param ContainerBuilder $container
     *
     * @api
     */
    public function process(ContainerBuilder $container)
    {
        $service_list = $container->findTaggedServiceIds(
            'tbf_route.loader'
        );
        $config_def = $container->getDefinition('tbf_route.config');
        $output = array();
        foreach ($service_list as $service_id=>$service_attributes) {
            $output[] = new Reference($service_id);
        }
        $config_def->setArguments(array($output));
    }
}
